
#include<bits/stdc++.h>
using namespace std;

const int MAXN=1000+10;

int arr[MAXN];

int Fun1(int n){
    int answer;
    if(n==0){
        answer=1;
    }else{
        answer=1;
        for(int i=0;i<n;++i){
            if(arr[i]<arr[n]){
                answer=max(answer,Fun1(i)+1);
            }
        }
    }
    return answer;
}

int memo[MAXN];
int Fun2(int n){
    if(memo[n]!=-1){
        return memo[n];
    }
    int answer;
    if(n==0){
        answer=1;
    }else{
        answer=1;
        for(int i=0;i<n;++i){
            if(arr[i]<arr[n]){
                answer=max(answer,Fun2(i)+1);
            }
        }
    }
    memo[n]=answer;
    return answer;
}

int dp[MAXN];
void Fun3(int n){
    for(int j=0;j<n;++j){
        int answer;
        if(j==0){
            answer=1;
        }else{
            answer=1;
            for(int i=0;i<j;++i){
                if(arr[i]<arr[j]){
                    answer=max(answer,dp[i]+1);
                }
            }
        }
        dp[j]=answer;
    }
    return;
}


int main(){
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;++i){
        scanf("%d",&arr[i]);
    }

    //recursive，朴素递归超时O(2^n)
    /*int maximum=0;
    for(int i=0;i<n;++i){
        maximum=max(maximum,Fun1(i));
    }
    printf("%d\n",maximum);
    */

    //recursive+memorize,递归+记忆O(n^2)
    /*fill(memo,memo+n,-1);
    int maximum=0;
    for(int i=0;i<n;++i){
        maximum=max(maximum,Fun2(i));
    }
    printf("%d\n",maximum);
    */

    //recurrent,递推求解O(n^2)
    fill(dp,dp+n,-1);
    int maximum=0;
    Fun3(n);
    for(int i=0;i<n;++i){
        maximum=max(maximum,dp[i]);
    }
    printf("%d\n",maximum);

    return 0;
}


